import 'dart:io';
import 'package:common_utils/common_utils.dart';
import 'package:catguard/utils/singleton_manager.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:get_storage/get_storage.dart';
import 'package:intl/date_symbol_data_local.dart';

import 'application.dart';
import 'config/config.dart';
import 'config/env_config.dart';

void main() {
  //设置透明状态栏
  if (Platform.isAndroid) {
    SystemChrome.setSystemUIOverlayStyle(
      const SystemUiOverlayStyle(
        statusBarColor: Colors.transparent,
        systemNavigationBarColor: Color(0xFFFFFFFF),
        systemNavigationBarDividerColor: null,
        systemNavigationBarIconBrightness: Brightness.dark,
        statusBarIconBrightness: Brightness.dark,
        statusBarBrightness: Brightness.dark,
      ),
    );
  } else {
    SystemChrome.setSystemUIOverlayStyle(
      const SystemUiOverlayStyle(
        statusBarColor: Colors.transparent,
        systemNavigationBarColor: Color(0xFFFFFFFF),
        systemNavigationBarDividerColor: null,
        systemNavigationBarIconBrightness: Brightness.light,
        statusBarIconBrightness: Brightness.light,
        statusBarBrightness: Brightness.light,
      ),
    );
  }

  getLanguage() async {
    final box = GetStorage();
    String current = box.read(Config.languageKey) ?? 'zh_CN';
    SingletonManager().appLanguage = current;
  }

  LogUtil.init(tag: 'CatGuard', isDebug: true, maxLen: 512);
  WidgetsFlutterBinding.ensureInitialized();
  //设置屏幕固定方向
  SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp]).then((_) async {
    // 初始化 GetStorage
    await GetStorage.init();
    await getLanguage();
    LogUtil.v('当前app语言=${SingletonManager().appLanguage}');
    Env.initEnvConfig();
    LogUtil.v('当前运行环境=${Env.appEnv}');
    await initializeDateFormatting('zh_CN',null);
    runApp(const Application());
  });
}
